<?php

require_once('../tcpdf/tcpdf.php');
require_once('../tcpdf/config/lang/eng.php');
include ('../genericos/translate.php');

class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES . 'logo_example.jpg';
        $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

}

// extend TCPF with custom functions
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

//$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 12);

// add a page
$pdf->AddPage();

// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
// create some HTML content
$procedimientos = $_GET['procedimientos'];
$productos = $_GET['productos'];
$fecha = $_GET['fecha'];
$centro = $_GET['centro'];
$paciente = $_GET['paciente'];
$empleado = $_GET['empleado'];
$total = $_GET['total'];
$desc = $_GET['desc'];
$totalneto = $_GET['totalneto'];
$cancelatotal = $_GET['cancelatotal'];
$abono = $_GET['abono'];
$saldo = $_GET['saldo'];
$saldoanterior = $_GET['saldoanterior'];




$html = '<table>
        <tr>
        <td><h2>' . _(fecha) . '</h2></td><td></td>
        </tr>
        <tr>
        <td>' . $fecha . '</td><td></td>
        </tr>
        <tr>
        <td><h2>' . _(centromedico) . '</h2></td><td></td>
        </tr>
        <tr>
        <td >' . $centro . '</td><td></td>
        </tr>
        <tr>
        <td><h2>' . _(empleado) . '</h2></td><td></td>
        </tr>
        <tr>
        <td>' . $empleado . '</td><td></td>
        </tr>
        <tr>
        <td><h2>' . _(paciente) . '</h2></td><td></td>
        </tr>
        <tr>
        <td>' . $paciente . '</td><td></td>
        </tr>
        <tr>
        <td><h2>' . _(detalle) . '</h2></td><td></td>
        </tr>
        <tr style="font-weight:bold;">
        <td  style="width: 35%;"> ' . _(procedimiento) . ' </td>
        <td> ' . _(precio) . '  </td>
         </tr>';

$procedimiento = split("-/", $procedimientos);

for ($i = 0; $i < count($procedimiento) - 1; $i++) {

    $detalle = split("_/", $procedimiento[$i]);

    $html .= '<tr><td>' . $detalle[0] . '</td>' . '<td>' . $detalle[1];

    if ($detalle[2] != "0") {
        $html .= ' -' . $detalle[2] . '%';
    }
    $html .= '</td></tr>';
}

if ($productos != "") {
    $html .= '<tr style="font-weight:bold;">
                    <td> ' . _(productos) . '  </td>
                    <td> ' . _(precio) . '  </td>
                    </tr>';
}

$producto = split("-/", $productos);
$detalle = "";
for ($i = 0; $i < count($producto) - 1; $i++) {

    $detalle = split("_/", $producto[$i]);


    $html .= '<tr><td>' . $detalle[0] . '-' . $detalle[1] . '</td>' . '<td>' . $detalle[2];
    if ($detalle[3] != "0") {
        $html .= ' -' . $detalle[3] . '%';
    }
    $html .= '</td></tr>';
}
$html .="<tr><td></td><td></td></tr>";
if ($desc != "") {
    $html .= '<tr><td>=' . _(subtotal) . '</td><td>' . $total . '</td><td></td></tr>';
    $html .= '<tr><td>=' . _(descuento) . '</td><td>' . $desc . '</td><td></td></tr>';
}

$html .= '<tr><td>=' . _(total) . '</td><td>' . $totalneto . '</td><td></td></tr>';

$html .="<tr><td></td><td></td></tr>";

if ($cancelatotal == "no") {

    if ($saldoanterior != "") {
        $html .= '<tr><td>=' . _(saldoanterior) . '</td><td>' . $saldoanterior . '</td><td></td></tr>';
    }
    $html .= '<tr><td>=' . _(abono) . '</td><td>' . $abono . '</td><td></td></tr>';

    $html .= '<tr><td>=' . _(saldo) . '</td><td>' . $saldo . '</td><td></td></tr>';
}



$html .= '<table>';



// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');


// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output($name, 'I');
//============================================================+
// END OF FILE
//============================================================+
?>

